<template>
  <div class="box">
    <a-layout>
      <a-layout>
        <div class="left">
          <a-layout-sider width="200" style="background: #fff">
            <p>项目架构</p>
            <p>强盛集团</p>
            <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree><img
              src="https://img.axureshop.com/0e/a4/ac/0ea4ac0fe33148ab863f5e2758608948/images/%E6%89%BF%E5%BB%BA%E5%95%86%E7%99%BB%E8%AE%B0/u391.png"
              alt="" @click="adddata">
          </a-layout-sider>
        </div>
        <div class="right">
          <a-layout style="padding: 0 24px 24px">
            <div class="list1">
              <span class="span1">承建商列表</span>
              <el-upload class="upload-demo" action="https://jsonplaceholder.typicode.com/posts/">
                <el-button size="small" type="primary" class="input1">导出</el-button>
              </el-upload>
            </div>
            <div class="list2">
              <span class="span2">搜索</span><input type="text" placeholder="请输入承建商名称/项目经理/联系手机" class="input2"
                v-model="firstone" />
              <span class="span2">承建商性质</span>

              <el-select v-model="secondone" placeholder="---请选择---" class="input4" clearable>
                <el-option v-for="item in ilist" :key="item" :label="item" :value="item">
                </el-option>
              </el-select>
              <input type="button" value="搜索" @click="searchnature" class="input3" />
            </div>
            <el-table :data="tableData.slice((page - 1) * limit, page * limit)" border style="width: 100%">
              <el-table-column fixed type="index" label="序号" width="60" header-align="center" align="center">
                <template #default="scope">
                  <span>{{ (page - 1) * limit + scope.$index + 1 }}</span>
                </template>
              </el-table-column>
              <el-table-column prop="name" label="承建商名称" width="100">
              </el-table-column>
              <el-table-column prop="nature" label="承建商性质" width="100">
              </el-table-column>
              <el-table-column prop="ziben" label="注册资本" width="130">
              </el-table-column>
              <el-table-column prop="daibiao" label="法定代表人" width="100">
              </el-table-column>
              <el-table-column prop="jingli" label="项目经理" width="100">
              </el-table-column>
              <el-table-column prop="phone" label="联系手机" width="100">
              </el-table-column>
              <el-table-column prop="enterdate" label="进场日期" width="100">
              </el-table-column>
              <el-table-column prop="godate" label="退场日期" width="100">
              </el-table-column>
              <el-table-column prop="caozuo" label="操作" width="240">
                <template #default="scope">
                  <el-button size="mini" @click="editdata(scope.row.id)">编辑</el-button>
                  <el-popconfirm confirmButtonText="确定" cancelButtonText="取消" icon="el-icon-info" iconColor="red"
                    title="这是一条数据确定删除吗？" @confirm="confirmEvent(scope.row.id)" @cancel="cancelEvent">
                    <template #reference>
                      <el-button>删除</el-button>
                    </template>
                  </el-popconfirm>

                  <el-button size="mini" @click="finddata(scope.row.name)">查看</el-button>
                </template>
              </el-table-column>
            </el-table>
            <dengjiedit v-show="isShowEdit" @hide="hideFn" :id="editid" @updatesuccess="successFn"></dengjiedit>
            <dengjiadd v-show="isShowadd" @hide="hideFn2" :id="addid" @updatesuccess="successFn2"></dengjiadd>
            <dengjifind v-show="isShowFind" @hide="hideFn1" :name="findname" @updatesuccess="successFn1"></dengjifind>
            <div class="list3">
              <!--分页组件-->
              <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
                :page-sizes="[4, 8, 12]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper"
                :total="total">
              </el-pagination>
            </div>
          </a-layout>
        </div>
      </a-layout>
    </a-layout>
  </div>
</template>
<script setup lang="ts">
import dengjiedit from "./dengjiedit.vue";
import dengjiadd from "./dengjiadd.vue";
import dengjifind from "./dengjifind.vue";
import service from "../../../utils/service";
import { reactive, ref } from "vue";
import { ElMessage } from "element-plus";
import "element-plus/dist/index.css";


const page = ref(1)
const limit = ref(4)
const total = ref(0);
interface itabledata {
  id: string;
  name: string;
  nature: string;
  ziben: string;
  daibiao: string;
  jingli: string;
  phone: string;
  enterdate: string;
  godate: string;
}
const data = [
  {
    label: 'XXXXX建设有限公司',
    children: [
      {
        label: 'XXXX项目1',
        children: [
          {
            label: '中建八局',
            children: [
              {
                label: '中铁二建',

              },
            ],
          },
        ],
      },
      {
        label: 'XXXX项目2',
        children: [
          {
            label: '中建六局',
            children: [
              {
                label: '中铁四建',

              },
            ],
          },
        ],
      },
    ],
  },
]
const tableData = reactive<itabledata[]>([]);



// 获取数据
const gettableData = () => {
  service({
    url: "contractorslist",
  }).then((res) => {
    tableData.length = 0;
    tableData.push(...res.data);
    total.value = res.data.length;


  });
};
gettableData();

// 分页
const handleSizeChange = (val: any) => {
  limit.value = val
}
const handleCurrentChange = (val: any) => {
  page.value = val
}
const firstone = ref()
const secondone = ref()
const ilist = reactive(["---请选择---", "总包单位", "分包单位", "监理单位"]);
// 点击搜索查看
const searchnature = () => {
  service({
    url: "contractorslist?q=" + firstone.value,
    method: "get",
    params:{
      "nature":secondone.value
    }

  }).then((res) => {
    firstone.value="";
    secondone.value=undefined;
    console.log(res);
    tableData.length = 0;
    tableData.push(...res.data);
    
  });

}
// 点击加号弹出框
const isShowadd = ref(false);
const addid = ref("");
const adddata = (name: string) => {
  isShowadd.value = true;
  findname.value = name;

};
const hideFn2 = () => {
  isShowadd.value = false;
};
const successFn2 = () => gettableData();
// 点击编辑弹出框
const isShowEdit = ref(false);
const editid = ref("");
const editdata = (id: string) => {
  isShowEdit.value = true;
  editid.value = id
};
const hideFn = () => {
  isShowEdit.value = false;
};
const successFn = () => gettableData();

// 点击查看弹出框
const isShowFind = ref(false);
const findname = ref("");
const finddata = (name: string) => {
  isShowFind.value = true;
  findname.value = name;

};
const hideFn1 = () => {
  isShowFind.value = false;
};
const successFn1 = () => gettableData();

// 删除单条数据
const confirmEvent = (id: string) => {
  service({
    url: "contractorslist/" + id,
    method: "delete",
  }).then((res) => {
    ElMessage({
      message: "删除单条数据成功！",
      type: "success",
    });

    gettableData();
  });
}
const cancelEvent = () => {
  console.log('confirm!')
}

</script>
<style scoped>
.box {
  background: #f6f7f9;
}

.left {
  width: 220px;
  height: 709px;
  background: #fff;
  /* border: 1px solid #999; */
  position: relative;
}

.left img {
  width: 17px;
  height: 17px;
  position: absolute;
  top: 84px;
  left: 156px;
}

.right {
  /* width: 1164.67px; */
  height: 709px;
  background: #fff;
  margin-left: 10px;
  /* border: 1px solid #999; */
}

#components-layout-demo-top-side-2 .logo {
  float: left;
  width: 120px;
  height: 31px;
  margin: 16px 24px 16px 0;
  background: rgba(255, 255, 255, 0.3);
}

.ant-row-rtl #components-layout-demo-top-side-2 .logo {
  float: right;
  margin: 16px 0 16px 24px;
}

.site-layout-background {
  background: #fff;
}

p {
  color: #666;
}

.list1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.list2 {
  margin-top: 10px;
}

.input1 {
  width: 72px;
  height: 30px;
  background: inherit;
  background-color: rgba(255, 255, 255, 1);
  box-sizing: border-box;
  border-width: 1px;
  border-style: solid;
  border-color: rgba(121, 121, 121, 1);
  border-radius: 5px;
  -moz-box-shadow: none;
  -webkit-box-shadow: none;
  box-shadow: none;
  font-family: "PingFangSC-Regular", "PingFang SC";
  font-weight: 400;
  font-style: normal;
  font-size: 12px;
  color: #666;
}

.span1 {
  font-weight: 700;
  font-style: normal;
  font-size: 16px;
  color: #666;
}

.span2 {
  font-size: 12px;
  color: #666;
  margin-left: 10px;
}

.input2 {
  width: 244px;
  height: 35px;
  border-width: 1px;
  border-color: #1abc9c;
  font-size: 12px;

  margin-left: 30px;
  color: rgb(204, 204, 204);

}

.input3 {
  width: 71px;
  height: 35px;
  background: inherit;
  background-color: rgba(59, 177, 156, 1);
  box-sizing: border-box;
  border-width: 1px;
  border-style: solid;
  border-color: rgba(26, 188, 156, 1);
  border-radius: 5px;
  font-weight: 400;
  font-style: normal;
  font-size: 12px;
  color: #ffffff;
  margin-left: 15px;
}

.input4 {
  width: 177px;
  height: 35px;
  background-color: rgba(255, 255, 255, 0);
  /* box-sizing: border-box; */
  border: 1px solid #999;
  border-radius: 3px;
  margin-left: 10px;
}

.el-table {
  margin-top: 10px;
  text-align: center;
}

.cell {
  font-size: 12px;
  color: #666;
  font-weight: 600;
  text-align: center;
}

.el-pagination {
  justify-content: flex-end;
}

.span3 {
  width: 40px;
  height: 22px;
  line-height: 22px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.988235294117647);
  background: #999999;
  border-radius: 5px;
  text-align: center;
}

.span4 {
  width: 60px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.988235294117647);
  background-color: rgba(153, 153, 153, 1);
  border-radius: 5px;
}

.span5 {
  width: 114px;
  height: 20px;
  font-size: 12px;
  color: rgb(102, 102, 102);
  margin-left: 10px;
}

.list3 {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 15px;
}
</style>
